package com.itheima.bigevent.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.itheima.bigevent.annotation.State;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.groups.Default;
import lombok.Data;
import org.hibernate.validator.constraints.URL;

import java.time.LocalDateTime;

@Data
public class Article {
    /**
     * 主键ID
     */
    @NotNull(message = "id不能为空", groups = {Update.class})
    @Min(value = 1, message = "id必须大于0", groups = {Update.class})
    private Integer id;
    /**
     * 文章标题
     */
    @NotEmpty(message = "标题不能为空")
    @Pattern(message = "标题只能是1至10位的非空字符", regexp = "^\\S{1,10}$")
    private String title;
    /**
     * 文章内容
     */
    @NotEmpty(message = "内容不能为空")
    private String content;
    /**
     * 封面图像
     */
    @NotEmpty(message = "封面图像不能为空")
    @URL(message = "封面图像URL格式不正确")
    private String coverImg;
    /**
     * 发布状态 已发布|草稿
     */
    @State
    private String state;
    /**
     * 文章分类id
     */
    @NotNull(message = "文章所属分类不能为空")
    @Min(value = 1, message = "文章所属分类不正确")
    private Integer categoryId;
    /**
     * 创建人ID
     */
    private Integer createUser;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public interface Add extends Default {}

    public interface Update extends Default {}
}
